<template>
	<view>
		<headerinfo></headerinfo>
		<u-navbar title="分享名片" :placeholder="true" :bgColor="bgColor" :titleStyle="titleStyle"></u-navbar>

		<view class="erweima">
			<image :show-menu-by-longpress="true" :src="xcxImg" mode="widthFix"></image>
			<!-- <tki-qrcode cid="qrcode1" ref="qrcode" :val="val" :icon="icon" :size="size" :onval="onval"
				:loadMake="loadMake" :usingComponents="true" @result="qrR" /> -->
		</view>
		<view  class="btn">
			<button open-type="share" class="shareBtn"></button>直接分享
		</view>
		

	</view>
</template>

<script>
	// import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
	export default {
		components: {
			// tkiQrcode
		},
		data() {
			return {
				titleStyle: {
					color: '#fff'
				},
				bgColor: '#de4849',
				val: '', // 要生成的二维码值
				size: 350, // 二维码大小
				onval: true, // val值变化时自动重新生成二维码
				loadMake: false, // 组件加载完成后自动生成二维码
				src: '', // 二维码生成后的图片地址或base64
				username: "",
				icon: '',
				id: ''
			}
		},
		onLoad(e) {
			console.log(e)
			if (e.id) {
				this.username = e.username ? e.username : ''
				this.id = e.id
				this.crateImg()
			}
		},
		methods: {
			crateImg() {

				let path = ''
				if (this.username) {
					path = `/pages/card/index?username=${this.username}&id=${this.id}`
				} else {
					path = `/pages/card/index?id=${this.id}`
				}
				
				let data = {
					envVersion: 'trial',
					path,
					width: '430',
					base: {
						requestId: Math.floor(Math.random() * 1000000000) + '',
						clientId: 'minghui',
						debugMore: false
					}
				}
				var that = this
				
				uni.request({
          url: `${apiBaseURL}/getWxWpACode`,
					data: data,
					responseType: 'arraybuffer', 
					method: "POST",
					header: {
						'content-type': 'application/json'
					},
					success(res) {
						console.log(res)
						const arrayBuffer = new Uint8Array(res.data) 
						that.xcxImg = 'data:image/png;base64,' + uni.arrayBufferToBase64(arrayBuffer)
					},
					fail(e) {}
				})

				// this.$api.myInfo().then(res => {
				// 	console.log(res)
				// 	if (res.avatar) {
				// 		uni.downloadFile({
				// 			url: res.avatar, //仅为示例，并非真实的资源
				// 			success: (res) => {
				// 				console.log(res)
				// 				this.icon = res.tempFilePath
				// 				this.$nextTick(() => {
				// 					this.val = path
				// 				})

				// 			}
				// 		});
				// 	} else {

				// 		this.$nextTick(() => {
				// 			this.val = path
				// 		})
				// 	}
				// })

			},
			// qrR(res) {
			// 	console.log(res)
			// 	this.src = res
			// },
		}
	};
</script>


<style lang="scss">
	.erweima {
		width: 350rpx;
		margin: 40rpx auto;
		display: block;
	}
</style>